//
// Created by Administrator on 2023/5/28.
//
#pragma once
#ifndef MAX_BUTTON_H
#define MAX_BUTTON_H

#include <QPushButton>
#include <QMouseEvent>
#include "../../Qss/Max_Button_Q.h"


template <typename Owner>
class Max_Button: public QPushButton
{
public:
    Max_Button(Owner* owner);


    Max_Button(Owner* owner, bool activation);


    ~Max_Button();


    void mousePressEvent(QMouseEvent* event);
    void mouseReleaseEvent(QMouseEvent* event);



    void Profile(bool activation);


    void Redraw();



private:
    Max_Button();


    Owner* owner;


    int owner_topleft_x;
    int owner_topleft_y;

    int owner_width;
    int owner_height;


    bool size_press {false};
    bool activation;


    const int width {15};
    const int height {15};

};
template <typename Owner>
Max_Button<Owner>::Max_Button(Owner* owner):
        owner(owner), activation(false)
{
    this->Profile(this->activation);
}


template <typename Owner>
Max_Button<Owner>::Max_Button(Owner* owner, bool activation):
        owner(owner), activation(activation)
{
    this->Profile(this->activation);
}


template <typename Owner>
Max_Button<Owner>::Max_Button(){}


template <typename Owner>
Max_Button<Owner>::~Max_Button(){}


template <typename Owner>
void Max_Button<Owner>::Profile(bool activation)
{
    if (!activation)
    {
        this->setParent(this->owner);


        this->resize(this->width, this->height);


        this->setObjectName(QString("Max_Button"));


        this->setStyleSheet(max_q_f);


        this->move(this->owner->geometry().width() - 45, 7);


        //this->setMouseTracking(true);
    }
    else
    {
        this->setParent(this->owner);


        this->resize(this->width, this->height);


        this->setObjectName(QString("Max_Button"));


        this->setStyleSheet(max_q_t);


        this->move(this->owner->geometry().width() - 45, 7);
    }


}


template <typename Owner>
void Max_Button<Owner>::mousePressEvent(QMouseEvent* event)
{
    if (event->button() == Qt::LeftButton)
    {
    }
}


template <typename Owner>
void Max_Button<Owner>::mouseReleaseEvent(QMouseEvent* event)
{
    if (this->size_press == false && !this->activation)
    {
        this->owner_topleft_x = this->owner->geometry().topLeft().x();
        this->owner_topleft_y = this->owner->geometry().topLeft().y();


        this->owner_width = this->owner->geometry().width();
        this->owner_height = this->owner->geometry().height();


        this->owner->move(0, 0);
        this->owner->resize(1920, 1040);
        this->size_press = true;
    }
    else if(this->size_press)
    {
        this->owner->move(this->owner_topleft_x, this->owner_topleft_y);
        this->owner->resize(this->owner_width, this->owner_height);
        this->size_press = false;
    }
}


template <typename Owner>
void Max_Button<Owner>::Redraw()
{
    this->resize(this->width, this->height);
    this->move(this->owner->geometry().width() - 45, 7);
}






#endif //BASE_WIDGET_MAX_BUTTON_H
